
import talib
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt


def macd_demo():
    close = np.random.random(100)
    macd, macdsignal, macdhist = talib.MACD(close, fastperiod=12, slowperiod=26, signalperiod=9)
    df = pd.DataFrame(columns=['close', 'macd', 'macdsignal', 'macdhist'])
    df['close'] = close
    df['macd'] = macd
    df['macdsignal'] = macdsignal
    df['macdhist'] = macdhist
    df.plot()
    plt.show()
    print(df)


def boll_demo():
    close = np.random.random(100)
    upper, middle, lower = talib.BBANDS(close, matype=talib.MA_Type.T3)
    df = pd.DataFrame(columns=['close', 'upper', 'middle', 'lower'])
    df['close'] = close
    df['upper'] = upper
    df['middle'] = middle
    df['lower'] = lower
    df.plot()
    plt.show()
    print(df)


if __name__ == '__main__':
    macd_demo()
    # boll_demo()